package com.epoch.client.view;

/*
 * 用户注册界面
 */


import com.epoch.client.kernel.listener.RegisterListener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class ClientRegisterJFrame extends JFrame {

    ClientRegisterJFrame() {
        JFrame frame = new JFrame("注册账号");
        frame.setIconImage((new ImageIcon(this.getClass().getResource("/imgs/login_title.png"))).getImage());
        frame.setLayout(null);
        frame.getContentPane().setBackground(new Color(193,210,240));

        JLabel nameStr = new JLabel("用户名:");
        nameStr.setBounds(50, 40, 100, 25);
        frame.add(nameStr);

        JLabel passwordStr = new JLabel("密码:");
        passwordStr.setBounds(50, 100, 100, 25);
        frame.add(passwordStr);

        JLabel confrimStr = new JLabel("确认密码:");
        confrimStr.setBounds(50, 160, 100, 25);
        frame.add(confrimStr);


        JTextField userName = new JTextField();
        userName.setBounds(150, 40, 150, 25);
        frame.add(userName);

        JPasswordField password = new JPasswordField();
        password.setBounds(150, 100, 150, 25);
        frame.add(password);

        JPasswordField confrimPassword = new JPasswordField();
        confrimPassword.setBounds(150, 160, 150, 25);
        frame.add(confrimPassword);

        JButton buttonregister = new JButton("注 册");
        buttonregister.setBounds(65, 200, 70, 25);
        buttonregister.setBackground(new Color(180,220,230));
        frame.add(buttonregister);

        JButton buttonBack = new JButton("返 回");
        buttonBack.setBounds(265,200,70,25);
        buttonBack.setBackground(new Color(180,220,230));
        frame.add(buttonBack);

        frame.setBounds(568, 272, 400, 320);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

        //为注册按钮增加监听器
        buttonregister.addActionListener(new RegisterListener(userName,password,confrimPassword,frame));
        buttonBack.addActionListener((event) -> {
            if(event.getSource() == buttonBack) {
                frame.dispose();
                new ClientLoginJFrame();
            }
        });
    }
}
